package br.com.wepa.webapps.logger;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

public class TraceLogger {
	public static final String ENTERING = "ENTERING";

	public static final String EXITING = "EXITING";

	public static final String ERROR = "ERROR";

	protected static final Logger logger = Logger.getRootLogger();

	protected Class clazz;

	protected SimpleDateFormat format = new SimpleDateFormat(
			"EEE, dd/MM/yyyy HH:mm:ss.SSSSSSSSSS");

	public TraceLogger(Class clazz) {
		this.clazz = clazz;
	}

	public void error(Object msg, Throwable exc) {
		logger.info(format.format(new Date()) + " - (" + ERROR + ") " + clazz);
		logger.info(msg, exc);
	}

	public void log(Object... objs) {
		logger.info(format.format(new Date()) + " - " + clazz);

		if (objs == null) {
			return;
		}

		for (Object obj : objs) {
			logger.info("\t" + obj);
		}

	}

	public void warning(Object... objs) {
		logger.warn(format.format(new Date()) + " - " + clazz);

		if (objs == null) {
			return;
		}

		for (Object obj : objs) {
			logger.warn("\t" + obj);
		}
	}

	public void fatal(Object... objs) {
		logger.fatal(format.format(new Date()) + " - " + clazz);

		if (objs == null) {
			return;
		}

		for (Object obj : objs) {
			logger.fatal("\t" + obj);
		}
	}

	public void entering(Object... objs) {
		logger.info(format.format(new Date()) + " - (" + ENTERING + ") "
				+ clazz);

		if (objs == null) {
			return;
		}

		for (Object obj : objs) {
			logger.info("\t" + obj);
		}
	}

	public void exiting(Object... objs) {
		logger
				.info(format.format(new Date()) + " - (" + EXITING + ") "
						+ clazz);

		if (objs == null) {
			return;
		}

		for (Object obj : objs) {
			logger.info("\t" + obj);
		}

		return;
	}
}
